/**  
 * @Title: MsgController.java
 * @Package com.silverbox.sweeporder.controller.msg
 * @author litao
 * @date 2018年1月3日
 */
package com.silverbox.sweeporder.controller.msg;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.silverbox.core.result.CoreResponse;
import com.silverbox.core.result.CoreResponse.StatusInfo;
import com.silverbox.sweeporder.controller.msg.vo.SendMsgEntryVO;
import com.silverbox.sweeporder.service.webmsg.WebMsgService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * ClassName: MsgController
 * 
 * @author litao
 * @date 2018年1月3日
 */
@Controller
@RequestMapping("msg")
@Api(tags={"发送消息接口"})
public class MsgController {

	@Autowired
	private WebMsgService webMsgService;

	@RequestMapping(value = "sendMsg", method = RequestMethod.POST)
	@ResponseBody
	@ApiOperation(value = "向商家消息服务器发送消息(可调用)")
	public CoreResponse<StatusInfo> sendMsg(HttpServletRequest request, HttpSession session,
			@RequestBody(required=true) SendMsgEntryVO sendMsgEntry) {
		CoreResponse<StatusInfo> res = new CoreResponse<StatusInfo>();
		if (sendMsgEntry==null || sendMsgEntry.getStoreId() == null || sendMsgEntry.getMsg()==null) {
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}
		webMsgService.sendMsg(sendMsgEntry);
		return res;

	}
	
	@RequestMapping(value = "saveMsgTest", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "test环境测试消息推送(可调用)")
	public CoreResponse<StatusInfo> saveMsgTest(HttpServletRequest request, HttpSession session,
			@RequestParam(required=true) String orderNum,@RequestParam(required=true) Integer times,
			@RequestParam(required=false) Long hostMachineId) {
		CoreResponse<StatusInfo> res = new CoreResponse<StatusInfo>();
		if (orderNum == null || times == null) {
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}
		res = webMsgService.saveMsg(orderNum,times,hostMachineId);
		return res;

	}
	
	@RequestMapping(value = "deleteMsgTest", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value = "test环境测试消息删除(可调用)")
	public CoreResponse<StatusInfo> deleteMsgTest(HttpServletRequest request, HttpSession session,
			@RequestParam(required=true) Integer storeId,@RequestParam(required=false) Long machineId){
		CoreResponse<StatusInfo> res = new CoreResponse<StatusInfo>();
		if (storeId == null ) {
			res.setStatusInfo(StatusInfo.ERROR_40002);
			return res;
		}	
		res = webMsgService.deleteMsg(storeId,machineId);
		return res;
	}
}
